package com.jinmdz.fmis.mapper.mapper.provider;

import com.jinmdz.fmis.mapper.entity.CremationCertificatePrintingHistoryEntity;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;

/**
 * 火化证打印历史记录表Provider
 *
 * @author generator
 * @date 2020-03-12 17:08
 */
public class CremationCertificatePrintingHistoryProvider {

    /**
     * 增加CremationCertificatePrintingHistory
     *
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-03-12 17:08
     */
    public String insertCremationCertificatePrintingHistory(@Param("entity") CremationCertificatePrintingHistoryEntity entity) {
        return new SQL() {
            {
                INSERT_INTO(" cremation_certificate_printing_history ");

                if (entity.getDeleted() != null) {
                    VALUES(" deleted ", " #{entity.deleted,jdbcType=TINYINT} ");
                }

                VALUES(" business_code ", " #{entity.businessCode,jdbcType=VARCHAR} ");
                VALUES(" member_id ", " #{entity.memberId,jdbcType=INTEGER} ");
                VALUES(" member_name ", " #{entity.memberName,jdbcType=VARCHAR} ");
                VALUES(" member_gender_code ", " #{entity.memberGenderCode,jdbcType=SMALLINT} ");
                VALUES(" certificate_type_code ", " #{entity.certificateTypeCode,jdbcType=SMALLINT} ");
                VALUES(" certificate_no ", " #{entity.certificateNo,jdbcType=VARCHAR} ");
                VALUES(" member_relation ", " #{entity.memberRelation,jdbcType=VARCHAR} ");
                VALUES(" mobile_phone ", " #{entity.mobilePhone,jdbcType=VARCHAR} ");
                VALUES(" other_phone ", " #{entity.otherPhone,jdbcType=VARCHAR} ");
                VALUES(" address ", " #{entity.address,jdbcType=VARCHAR} ");
                VALUES(" cremation_old_no ", " #{entity.cremationOldNo,jdbcType=VARCHAR} ");
                VALUES(" cremation_new_no ", " #{entity.cremationNewNo,jdbcType=VARCHAR} ");
                VALUES(" operation_type_code ", " #{entity.operationTypeCode,jdbcType=SMALLINT} ");
                VALUES(" operation_time ", " #{entity.operationTime,jdbcType=TIMESTAMP} ");
                VALUES(" operation_cause ", " #{entity.operationCause,jdbcType=VARCHAR} ");
                VALUES(" remark ", " #{entity.remark} ");
                VALUES(" funeral_parlour_code ", " #{entity.funeralParlourCode,jdbcType=VARCHAR} ");
                VALUES(" create_user_id ", " #{entity.createUserId,jdbcType=INTEGER} ");

                if (entity.getUnmodified() != null) {
                    VALUES(" unmodified ", " #{entity.unmodified,jdbcType=TINYINT} ");
                }

                VALUES(" modified_user_id ", " #{entity.modifiedUserId,jdbcType=INTEGER} ");
                VALUES(" version ", " unix_timestamp(now()) ");
            }
        }.toString();
    }

    /**
     * 修改CremationCertificatePrintingHistory
     *
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-03-12 17:08
     */
    public String updateCremationCertificatePrintingHistory(@Param("entity") CremationCertificatePrintingHistoryEntity entity) {
        return new SQL() {
            {
                UPDATE(" cremation_certificate_printing_history ");

                if (entity.getDeleted() != null) {
                    SET(" deleted = #{entity.deleted,jdbcType=TINYINT} ");
                }

                SET(" business_code = #{entity.businessCode,jdbcType=VARCHAR} ");
                SET(" member_id = #{entity.memberId,jdbcType=INTEGER} ");
                SET(" member_name = #{entity.memberName,jdbcType=VARCHAR} ");
                SET(" member_gender_code = #{entity.memberGenderCode,jdbcType=SMALLINT} ");
                SET(" certificate_type_code = #{entity.certificateTypeCode,jdbcType=SMALLINT} ");
                SET(" certificate_no = #{entity.certificateNo,jdbcType=VARCHAR} ");
                SET(" member_relation = #{entity.memberRelation,jdbcType=VARCHAR} ");
                SET(" mobile_phone = #{entity.mobilePhone,jdbcType=VARCHAR} ");
                SET(" other_phone = #{entity.otherPhone,jdbcType=VARCHAR} ");
                SET(" address = #{entity.address,jdbcType=VARCHAR} ");
                SET(" cremation_old_no = #{entity.cremationOldNo,jdbcType=VARCHAR} ");
                SET(" cremation_new_no = #{entity.cremationNewNo,jdbcType=VARCHAR} ");
                SET(" operation_type_code = #{entity.operationTypeCode,jdbcType=SMALLINT} ");
                SET(" operation_time = #{entity.operationTime,jdbcType=TIMESTAMP} ");
                SET(" operation_cause = #{entity.operationCause,jdbcType=VARCHAR} ");
                SET(" remark = #{entity.remark} ");
                SET(" funeral_parlour_code = #{entity.funeralParlourCode,jdbcType=VARCHAR} ");

                if (entity.getUnmodified() != null) {
                    SET(" unmodified = #{entity.unmodified,jdbcType=TINYINT} ");
                }

                SET(" modified_user_id = #{entity.modifiedUserId,jdbcType=INTEGER} ");
                SET(" version = unix_timestamp(now()) ");
                WHERE(" id = #{entity.id,jdbcType=INTEGER} ");
                WHERE(" unmodified = 0 ");
                WHERE(" version = #{entity.version,jdbcType=INTEGER} ");
            }
        }.toString();
    }

    /**
     * 查询CremationCertificatePrintingHistory列表
     *
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-03-12 17:08
     */
    public String listCremationCertificatePrintingHistory(@Param("entity") CremationCertificatePrintingHistoryEntity entity) {
        return new SQL() {
            {
                StringBuilder builder = new StringBuilder();
                builder.append(" id,deleted,business_code,member_id,member_name,member_gender_code,certificate_type_code,certificate_no,member_relation,mobile_phone,other_phone,address,cremation_old_no,cremation_new_no,operation_type_code,operation_time,operation_cause,remark,funeral_parlour_code,create_user_id,gmt_create,unmodified,modified_user_id,gmt_modified,version ");
                SELECT(builder.toString());
                FROM(" cremation_certificate_printing_history ");

                if (entity.getBusinessCode() != null) {
                    WHERE(" business_code = #{entity.businessCode,jdbcType=VARCHAR} ");
                }

                if (entity.getMemberId() != null) {
                    WHERE(" member_id = #{entity.memberId,jdbcType=INTEGER} ");
                }

                if (entity.getMemberName() != null) {
                    WHERE(" member_name = #{entity.memberName,jdbcType=VARCHAR} ");
                }

                if (entity.getMemberGenderCode() != null) {
                    WHERE(" member_gender_code = #{entity.memberGenderCode,jdbcType=SMALLINT} ");
                }

                if (entity.getCertificateTypeCode() != null) {
                    WHERE(" certificate_type_code = #{entity.certificateTypeCode,jdbcType=SMALLINT} ");
                }

                if (entity.getCertificateNo() != null) {
                    WHERE(" certificate_no = #{entity.certificateNo,jdbcType=VARCHAR} ");
                }

                if (entity.getMemberRelation() != null) {
                    WHERE(" member_relation = #{entity.memberRelation,jdbcType=VARCHAR} ");
                }

                if (entity.getMobilePhone() != null) {
                    WHERE(" mobile_phone = #{entity.mobilePhone,jdbcType=VARCHAR} ");
                }

                if (entity.getOtherPhone() != null) {
                    WHERE(" other_phone = #{entity.otherPhone,jdbcType=VARCHAR} ");
                }

                if (entity.getAddress() != null) {
                    WHERE(" address = #{entity.address,jdbcType=VARCHAR} ");
                }

                if (entity.getCremationOldNo() != null) {
                    WHERE(" cremation_old_no = #{entity.cremationOldNo,jdbcType=VARCHAR} ");
                }

                if (entity.getCremationNewNo() != null) {
                    WHERE(" cremation_new_no = #{entity.cremationNewNo,jdbcType=VARCHAR} ");
                }

                if (entity.getOperationTypeCode() != null) {
                    WHERE(" operation_type_code = #{entity.operationTypeCode,jdbcType=SMALLINT} ");
                }

                if (entity.getOperationTime() != null) {
                    WHERE(" operation_time = #{entity.operationTime,jdbcType=TIMESTAMP} ");
                }

                if (entity.getOperationCause() != null) {
                    WHERE(" operation_cause = #{entity.operationCause,jdbcType=VARCHAR} ");
                }

                if (entity.getRemark() != null) {
                    WHERE(" remark = #{entity.remark} ");
                }

                if (entity.getFuneralParlourCode() != null) {
                    WHERE(" funeral_parlour_code = #{entity.funeralParlourCode,jdbcType=VARCHAR} ");
                }

            }
        }.toString();
    }
}